<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE ScopedTypeVariables, CPP, BangPatterns #-}</span><span class="hs-cpp">
#if __GLASGOW_HASKELL__ &gt;= 703
</span><span class="hs-pragma">{-# LANGUAGE Unsafe #-}</span><span class="hs-cpp">
#endif
</span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- Copyright   : 2010-2011 Simon Meier, 2010 Jasper van der Jeugt</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- License     : BSD3-style (see LICENSE)</span><span>
</span><span id="line-9"></span><span class="hs-comment">--</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Maintainer  : Simon Meier &lt;iridcode@gmail.com&gt;</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Stability   : unstable, private</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Portability : GHC</span><span>
</span><span id="line-13"></span><span class="hs-comment">--</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- *Warning:* this module is internal. If you find that you need it please</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- contact the maintainers and explain what you are trying to do and discuss</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- what you would need in the public API. It is important that you do this as</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- the module may not be exposed at all in future releases.</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- The maintainers are glad to accept patches for further</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- standard encodings of standard Haskell values.</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- If you need to write your own builder primitives, then be aware that you are</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- writing code with /all safety belts off/; i.e.,</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- *this is the code that might make your application vulnerable to buffer-overflow attacks!*</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- The &quot;Data.ByteString.Builder.Prim.Tests&quot; module provides you with</span><span>
</span><span id="line-26"></span><span class="hs-comment">-- utilities for testing your encodings thoroughly.</span><span>
</span><span id="line-27"></span><span class="hs-comment">--</span><span>
</span><span id="line-28"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.ByteString.Builder.Prim.Internal</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-29"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Fixed-size builder primitives</span></span><span>
</span><span id="line-30"></span><span>    </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Size"><span class="hs-identifier">Size</span></a></span><span>
</span><span id="line-31"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier">FixedPrim</span></a></span><span>
</span><span id="line-32"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#fixedPrim"><span class="hs-identifier">fixedPrim</span></a></span><span>
</span><span id="line-33"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#size"><span class="hs-identifier">size</span></a></span><span>
</span><span id="line-34"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runF"><span class="hs-identifier">runF</span></a></span><span>
</span><span id="line-35"></span><span>
</span><span id="line-36"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyF"><span class="hs-identifier">emptyF</span></a></span><span>
</span><span id="line-37"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapF"><span class="hs-identifier">contramapF</span></a></span><span>
</span><span id="line-38"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairF"><span class="hs-identifier">pairF</span></a></span><span>
</span><span id="line-39"></span><span>  </span><span class="hs-comment">-- , liftIOF</span><span>
</span><span id="line-40"></span><span>
</span><span id="line-41"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#storableToF"><span class="hs-identifier">storableToF</span></a></span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Bounded-size builder primitives</span></span><span>
</span><span id="line-44"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier">BoundedPrim</span></a></span><span>
</span><span id="line-45"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#boundedPrim"><span class="hs-identifier">boundedPrim</span></a></span><span>
</span><span id="line-46"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#sizeBound"><span class="hs-identifier">sizeBound</span></a></span><span>
</span><span id="line-47"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runB"><span class="hs-identifier">runB</span></a></span><span>
</span><span id="line-48"></span><span>
</span><span id="line-49"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyB"><span class="hs-identifier">emptyB</span></a></span><span>
</span><span id="line-50"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-identifier">contramapB</span></a></span><span>
</span><span id="line-51"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairB"><span class="hs-identifier">pairB</span></a></span><span>
</span><span id="line-52"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#eitherB"><span class="hs-identifier">eitherB</span></a></span><span>
</span><span id="line-53"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#condB"><span class="hs-identifier">condB</span></a></span><span>
</span><span id="line-54"></span><span>
</span><span id="line-55"></span><span>  </span><span class="hs-comment">-- , liftIOB</span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#toB"><span class="hs-identifier">toB</span></a></span><span>
</span><span id="line-58"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#liftFixedToBounded"><span class="hs-identifier">liftFixedToBounded</span></a></span><span>
</span><span id="line-59"></span><span>
</span><span id="line-60"></span><span>  </span><span class="hs-comment">-- , withSizeFB</span><span>
</span><span id="line-61"></span><span>  </span><span class="hs-comment">-- , withSizeBB</span><span>
</span><span id="line-62"></span><span>
</span><span id="line-63"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Shared operators</span></span><span>
</span><span id="line-64"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%24%3C"><span class="hs-operator">(&gt;$&lt;)</span></a></span><span>
</span><span id="line-65"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%2A%3C"><span class="hs-operator">(&gt;*&lt;)</span></a></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span>  </span><span class="annot"><span class="hs-comment">-- * Deprecated</span></span><span>
</span><span id="line-68"></span><span>  </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#boudedPrim"><span class="hs-identifier">boudedPrim</span></a></span><span>
</span><span id="line-69"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-70"></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.html#"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Enum.html#maxBound"><span class="hs-identifier">maxBound</span></a></span><span class="hs-special">)</span><span class="hs-cpp">

#if !(__GLASGOW_HASKELL__ &gt;= 612)
</span><span class="hs-comment">-- ghc-6.10 and older do not support {-# INLINE CONLIKE #-}</span><span class="hs-cpp">
#define CONLIKE
</span><span class="hs-cpp">#endif
</span><span>
</span><span id="line-79"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- Supporting infrastructure</span><span>
</span><span id="line-81"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="hs-comment">-- | Contravariant functors as in the @contravariant@ package.</span><span>
</span><span id="line-84"></span><span class="hs-keyword">class</span><span> </span><span id="Contravariant"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Contravariant"><span class="hs-identifier hs-var">Contravariant</span></a></span></span><span> </span><span id="local-6989586621679070642"><span class="annot"><a href="#local-6989586621679070642"><span class="hs-identifier hs-type">f</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-85"></span><span>    </span><span id="local-6989586621679070640"><span id="local-6989586621679070641"><span id="contramap"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramap"><span class="hs-identifier hs-type">contramap</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070641"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070640"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070642"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070640"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070642"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070641"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-86"></span><span>
</span><span id="line-87"></span><span class="hs-keyword">infixl</span><span> </span><span class="hs-number">4</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%24%3C"><span class="hs-operator hs-type">&gt;$&lt;</span></a></span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="hs-comment">-- | A fmap-like operator for builder primitives, both bounded and fixed size.</span><span>
</span><span id="line-90"></span><span class="hs-comment">--</span><span>
</span><span id="line-91"></span><span class="hs-comment">-- Builder primitives are contravariant so it's like the normal fmap, but</span><span>
</span><span id="line-92"></span><span class="hs-comment">-- backwards (look at the type). (If it helps to remember, the operator symbol</span><span>
</span><span id="line-93"></span><span class="hs-comment">-- is like (&lt;$&gt;) but backwards.)</span><span>
</span><span id="line-94"></span><span class="hs-comment">--</span><span>
</span><span id="line-95"></span><span class="hs-comment">-- We can use it for example to prepend and/or append fixed values to an</span><span>
</span><span id="line-96"></span><span class="hs-comment">-- primitive.</span><span>
</span><span id="line-97"></span><span class="hs-comment">--</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- &gt; import Data.ByteString.Builder.Prim as P</span><span>
</span><span id="line-99"></span><span class="hs-comment">-- &gt;showEncoding ((\x -&gt; ('\'', (x, '\''))) &gt;$&lt; fixed3) 'x' = &quot;'x'&quot;</span><span>
</span><span id="line-100"></span><span class="hs-comment">-- &gt;  where</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- &gt;    fixed3 = P.char7 &gt;*&lt; P.char7 &gt;*&lt; P.char7</span><span>
</span><span id="line-102"></span><span class="hs-comment">--</span><span>
</span><span id="line-103"></span><span class="hs-comment">-- Note that the rather verbose syntax for composition stems from the</span><span>
</span><span id="line-104"></span><span class="hs-comment">-- requirement to be able to compute the size / size bound at compile time.</span><span>
</span><span id="line-105"></span><span class="hs-comment">--</span><span>
</span><span id="line-106"></span><span id="local-6989586621679070646"><span id="local-6989586621679070647"><span id="local-6989586621679070649"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%24%3C"><span class="hs-operator hs-type">(&gt;$&lt;)</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Contravariant"><span class="hs-identifier hs-type">Contravariant</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070649"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070647"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070646"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070649"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070646"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070649"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070647"><span class="hs-identifier hs-type">b</span></a></span></span></span></span><span>
</span><span id="line-107"></span><span id="%3E%24%3C"><span class="annot"><span class="annottext">&gt;$&lt; :: forall (f :: * -&gt; *) b a. Contravariant f =&gt; (b -&gt; a) -&gt; f a -&gt; f b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%24%3C"><span class="hs-operator hs-var hs-var">(&gt;$&lt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(b -&gt; a) -&gt; f a -&gt; f b
forall (f :: * -&gt; *) b a. Contravariant f =&gt; (b -&gt; a) -&gt; f a -&gt; f b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramap"><span class="hs-identifier hs-var">contramap</span></a></span><span>
</span><span id="line-108"></span><span>
</span><span id="line-109"></span><span>
</span><span id="line-110"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Contravariant"><span class="hs-identifier hs-type">Contravariant</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-111"></span><span>    </span><span id="local-6989586621679070533"><span class="annot"><span class="annottext">contramap :: forall b a. (b -&gt; a) -&gt; FixedPrim a -&gt; FixedPrim b
</span><a href="#local-6989586621679070533"><span class="hs-identifier hs-var hs-var hs-var hs-var">contramap</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(b -&gt; a) -&gt; FixedPrim a -&gt; FixedPrim b
forall b a. (b -&gt; a) -&gt; FixedPrim a -&gt; FixedPrim b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramapF"><span class="hs-identifier hs-var">contramapF</span></a></span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Contravariant"><span class="hs-identifier hs-type">Contravariant</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-114"></span><span>    </span><span id="local-6989586621679070530"><span class="annot"><span class="annottext">contramap :: forall b a. (b -&gt; a) -&gt; BoundedPrim a -&gt; BoundedPrim b
</span><a href="#local-6989586621679070530"><span class="hs-identifier hs-var hs-var hs-var hs-var">contramap</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(b -&gt; a) -&gt; BoundedPrim a -&gt; BoundedPrim b
forall b a. (b -&gt; a) -&gt; BoundedPrim a -&gt; BoundedPrim b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-identifier hs-var">contramapB</span></a></span><span>
</span><span id="line-115"></span><span>
</span><span id="line-116"></span><span>
</span><span id="line-117"></span><span class="hs-comment">-- | Type-constructors supporting lifting of type-products.</span><span>
</span><span id="line-118"></span><span class="hs-keyword">class</span><span> </span><span id="Monoidal"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Monoidal"><span class="hs-identifier hs-var">Monoidal</span></a></span></span><span> </span><span id="local-6989586621679070630"><span class="annot"><a href="#local-6989586621679070630"><span class="hs-identifier hs-type">f</span></a></span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-119"></span><span>    </span><span id="local-6989586621679070632"><span id="local-6989586621679070633"><span id="pair"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pair"><span class="hs-identifier hs-type">pair</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679070630"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070633"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070630"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070632"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070630"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070633"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679070632"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-120"></span><span>
</span><span id="line-121"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Monoidal"><span class="hs-identifier hs-type">Monoidal</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-122"></span><span>    </span><span id="local-6989586621679070525"><span class="annot"><span class="annottext">pair :: forall a b. FixedPrim a -&gt; FixedPrim b -&gt; FixedPrim (a, b)
</span><a href="#local-6989586621679070525"><span class="hs-identifier hs-var hs-var hs-var hs-var">pair</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FixedPrim a -&gt; FixedPrim b -&gt; FixedPrim (a, b)
forall a b. FixedPrim a -&gt; FixedPrim b -&gt; FixedPrim (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#pairF"><span class="hs-identifier hs-var">pairF</span></a></span><span>
</span><span id="line-123"></span><span>
</span><span id="line-124"></span><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Monoidal"><span class="hs-identifier hs-type">Monoidal</span></a></span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-125"></span><span>    </span><span id="local-6989586621679070522"><span class="annot"><span class="annottext">pair :: forall a b. BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (a, b)
</span><a href="#local-6989586621679070522"><span class="hs-identifier hs-var hs-var hs-var hs-var">pair</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (a, b)
forall a b. BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#pairB"><span class="hs-identifier hs-var">pairB</span></a></span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span class="hs-keyword">infixr</span><span> </span><span class="hs-number">5</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%2A%3C"><span class="hs-operator hs-type">&gt;*&lt;</span></a></span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="hs-comment">-- | A pairing/concatenation operator for builder primitives, both bounded and</span><span>
</span><span id="line-130"></span><span class="hs-comment">-- fixed size.</span><span>
</span><span id="line-131"></span><span class="hs-comment">--</span><span>
</span><span id="line-132"></span><span class="hs-comment">-- For example,</span><span>
</span><span id="line-133"></span><span class="hs-comment">--</span><span>
</span><span id="line-134"></span><span class="hs-comment">-- &gt; toLazyByteString (primFixed (char7 &gt;*&lt; char7) ('x','y')) = &quot;xy&quot;</span><span>
</span><span id="line-135"></span><span class="hs-comment">--</span><span>
</span><span id="line-136"></span><span class="hs-comment">-- We can combine multiple primitives using '&gt;*&lt;' multiple times.</span><span>
</span><span id="line-137"></span><span class="hs-comment">--</span><span>
</span><span id="line-138"></span><span class="hs-comment">-- &gt; toLazyByteString (primFixed (char7 &gt;*&lt; char7 &gt;*&lt; char7) ('x',('y','z'))) = &quot;xyz&quot;</span><span>
</span><span id="line-139"></span><span class="hs-comment">--</span><span>
</span><span id="line-140"></span><span id="local-6989586621679070623"><span id="local-6989586621679070624"><span id="local-6989586621679070625"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%2A%3C"><span class="hs-operator hs-type">(&gt;*&lt;)</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Monoidal"><span class="hs-identifier hs-type">Monoidal</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070625"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070625"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070624"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070625"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070623"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070625"><span class="hs-identifier hs-type">f</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070624"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679070623"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span></span><span>
</span><span id="line-141"></span><span id="%3E%2A%3C"><span class="annot"><span class="annottext">&gt;*&lt; :: forall (f :: * -&gt; *) a b. Monoidal f =&gt; f a -&gt; f b -&gt; f (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#%3E%2A%3C"><span class="hs-operator hs-var hs-var">(&gt;*&lt;)</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">f a -&gt; f b -&gt; f (a, b)
forall (f :: * -&gt; *) a b. Monoidal f =&gt; f a -&gt; f b -&gt; f (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#pair"><span class="hs-identifier hs-var">pair</span></a></span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span>
</span><span id="line-144"></span><span class="hs-comment">-- | The type used for sizes and sizeBounds of sizes.</span><span>
</span><span id="line-145"></span><span class="hs-keyword">type</span><span> </span><span id="Size"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#Size"><span class="hs-identifier hs-var">Size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-146"></span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-149"></span><span class="hs-comment">-- Fixed-size builder primitives</span><span>
</span><span id="line-150"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span class="hs-comment">-- | A builder primitive that always results in a sequence of bytes of a</span><span>
</span><span id="line-153"></span><span class="hs-comment">-- pre-determined, fixed size.</span><span>
</span><span id="line-154"></span><span class="hs-keyword">data</span><span> </span><span id="FixedPrim"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-var">FixedPrim</span></a></span></span><span> </span><span id="local-6989586621679070519"><span class="annot"><a href="#local-6989586621679070519"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="FP"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070519"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-155"></span><span>
</span><span id="line-156"></span><span id="local-6989586621679070619"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#fixedPrim"><span class="hs-identifier hs-type">fixedPrim</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070619"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070619"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-157"></span><span id="fixedPrim"><span class="annot"><span class="annottext">fixedPrim :: forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#fixedPrim"><span class="hs-identifier hs-var hs-var">fixedPrim</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span><span>
</span><span id="line-158"></span><span>
</span><span id="line-159"></span><span class="hs-comment">-- | The size of the sequences of bytes generated by this 'FixedPrim'.</span><span>
</span><span id="line-160"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#size"><span class="hs-pragma hs-type">size</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-161"></span><span id="local-6989586621679070617"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#size"><span class="hs-identifier hs-type">size</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070617"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-162"></span><span id="size"><span class="annot"><span class="annottext">size :: forall a. FixedPrim a -&gt; Int
</span><a href="Data.ByteString.Builder.Prim.Internal.html#size"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span id="local-6989586621679070517"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070517"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070517"><span class="hs-identifier hs-var">l</span></a></span><span>
</span><span id="line-163"></span><span>
</span><span id="line-164"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runF"><span class="hs-pragma hs-type">runF</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-165"></span><span id="local-6989586621679070615"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runF"><span class="hs-identifier hs-type">runF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070615"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070615"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-166"></span><span id="runF"><span class="annot"><span class="annottext">runF :: forall a. FixedPrim a -&gt; a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="Data.ByteString.Builder.Prim.Internal.html#runF"><span class="hs-identifier hs-var hs-var">runF</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679070516"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070516"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070516"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-167"></span><span>
</span><span id="line-168"></span><span class="hs-comment">-- | The 'FixedPrim' that always results in the zero-length sequence.</span><span>
</span><span id="line-169"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyF"><span class="hs-pragma hs-type">emptyF</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-170"></span><span id="local-6989586621679070613"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyF"><span class="hs-identifier hs-type">emptyF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070613"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-171"></span><span id="emptyF"><span class="annot"><span class="annottext">emptyF :: forall a. FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#emptyF"><span class="hs-identifier hs-var hs-var">emptyF</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-172"></span><span>
</span><span id="line-173"></span><span class="hs-comment">-- | Encode a pair by encoding its first component and then its second component.</span><span>
</span><span id="line-174"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairF"><span class="hs-pragma hs-type">pairF</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-175"></span><span id="local-6989586621679070512"><span id="local-6989586621679070513"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairF"><span class="hs-identifier hs-type">pairF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070513"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070512"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070513"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679070512"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-176"></span><span id="pairF"><span class="annot"><span class="annottext">pairF :: forall a b. FixedPrim a -&gt; FixedPrim b -&gt; FixedPrim (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#pairF"><span class="hs-identifier hs-var hs-var">pairF</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span id="local-6989586621679070508"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070508"><span class="hs-identifier hs-var">l1</span></a></span></span><span> </span><span id="local-6989586621679070507"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070507"><span class="hs-identifier hs-var">io1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span id="local-6989586621679070506"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070506"><span class="hs-identifier hs-var">l2</span></a></span></span><span> </span><span id="local-6989586621679070505"><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070505"><span class="hs-identifier hs-var">io2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-177"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; ((a, b) -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim (a, b)
forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070508"><span class="hs-identifier hs-var">l1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070506"><span class="hs-identifier hs-var">l2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679070503"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070503"><span class="hs-identifier hs-var">x1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679070502"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070502"><span class="hs-identifier hs-var">x2</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679070501"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070501"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070507"><span class="hs-identifier hs-var">io1</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070503"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070501"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO () -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070505"><span class="hs-identifier hs-var">io2</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070502"><span class="hs-identifier hs-var">x2</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070501"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070508"><span class="hs-identifier hs-var">l1</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-178"></span><span>
</span><span id="line-179"></span><span class="hs-comment">-- | Change a primitives such that it first applies a function to the value</span><span>
</span><span id="line-180"></span><span class="hs-comment">-- to be encoded.</span><span>
</span><span id="line-181"></span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- Note that primitives are 'Contravariant'</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- &lt;http://hackage.haskell.org/package/contravariant&gt;. Hence, the following</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- laws hold.</span><span>
</span><span id="line-185"></span><span class="hs-comment">--</span><span>
</span><span id="line-186"></span><span class="hs-comment">-- &gt;contramapF id = id</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- &gt;contramapF f . contramapF g = contramapF (g . f)</span><span>
</span><span id="line-188"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapF"><span class="hs-pragma hs-type">contramapF</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-189"></span><span id="local-6989586621679070498"><span id="local-6989586621679070499"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapF"><span class="hs-identifier hs-type">contramapF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070499"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070498"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070498"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070499"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-190"></span><span id="contramapF"><span class="annot"><span class="annottext">contramapF :: forall b a. (b -&gt; a) -&gt; FixedPrim a -&gt; FixedPrim b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramapF"><span class="hs-identifier hs-var hs-var">contramapF</span></a></span></span><span> </span><span id="local-6989586621679070497"><span class="annot"><span class="annottext">b -&gt; a
</span><a href="#local-6989586621679070497"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span id="local-6989586621679070496"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070496"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679070495"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070495"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (b -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim b
forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070496"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070494"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070494"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679070493"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070493"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070495"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; a
</span><a href="#local-6989586621679070497"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070494"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070493"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-191"></span><span>
</span><span id="line-192"></span><span class="hs-comment">-- | Convert a 'FixedPrim' to a 'BoundedPrim'.</span><span>
</span><span id="line-193"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#toB"><span class="hs-pragma hs-type">toB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-194"></span><span id="local-6989586621679070600"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#toB"><span class="hs-identifier hs-type">toB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070600"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070600"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-195"></span><span id="toB"><span class="annot"><span class="annottext">toB :: forall a. FixedPrim a -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#toB"><span class="hs-identifier hs-var hs-var">toB</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-type">FP</span></a></span><span> </span><span id="local-6989586621679070490"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070490"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679070489"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070489"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070490"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070487"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070487"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679070486"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070486"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO ()
</span><a href="#local-6989586621679070489"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070487"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070486"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO (Ptr Word8) -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070486"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070490"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-196"></span><span>
</span><span id="line-197"></span><span class="hs-comment">-- | Lift a 'FixedPrim' to a 'BoundedPrim'.</span><span>
</span><span id="line-198"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#liftFixedToBounded"><span class="hs-pragma hs-type">liftFixedToBounded</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-199"></span><span id="local-6989586621679070484"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#liftFixedToBounded"><span class="hs-identifier hs-type">liftFixedToBounded</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070484"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070484"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-200"></span><span id="liftFixedToBounded"><span class="annot"><span class="annottext">liftFixedToBounded :: forall a. FixedPrim a -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#liftFixedToBounded"><span class="hs-identifier hs-var hs-var">liftFixedToBounded</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FixedPrim a -&gt; BoundedPrim a
forall a. FixedPrim a -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#toB"><span class="hs-identifier hs-var">toB</span></a></span><span>
</span><span id="line-201"></span><span>
</span><span id="line-202"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#storableToF"><span class="hs-pragma hs-type">storableToF</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-203"></span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#storableToF"><span class="hs-identifier hs-type">storableToF</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679070593"><span class="annot"><a href="#local-6989586621679070593"><span class="hs-identifier hs-type">a</span></a></span></span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070593"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#FixedPrim"><span class="hs-identifier hs-type">FixedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070593"><span class="hs-identifier hs-type">a</span></a></span><span>
</span><span id="line-204"></span><span class="hs-comment">-- Not all architectures are forgiving of unaligned accesses; whitelist ones</span><span>
</span><span id="line-205"></span><span class="hs-comment">-- which are known not to trap (either to the kernel for emulation, or crash).</span><span class="hs-cpp">
#if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH) \
    || ((defined(arm_HOST_ARCH) || defined(aarch64_HOST_ARCH)) \
        &amp;&amp; defined(__ARM_FEATURE_UNALIGNED)) \
    || defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH) \
    || defined(powerpc64le_HOST_ARCH)
</span><span id="storableToF"><span class="annot"><span class="annottext">storableToF :: forall a. Storable a =&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#storableToF"><span class="hs-identifier hs-var hs-var">storableToF</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
forall a. Int -&gt; (a -&gt; Ptr Word8 -&gt; IO ()) -&gt; FixedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#FP"><span class="hs-identifier hs-var">FP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a -&gt; Int
forall a. Storable a =&gt; a -&gt; Int
</span><a href="../../base/src/Foreign.Storable.html#sizeOf"><span class="hs-identifier hs-var">sizeOf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">a
forall a. HasCallStack =&gt; a
</span><a href="../../base/src/GHC.Err.html#undefined"><span class="hs-identifier hs-var">undefined</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="#local-6989586621679070593"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070476"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070476"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679070475"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070475"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr a -&gt; a -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; a -&gt; IO ()
</span><a href="../../base/src/Foreign.Storable.html#poke"><span class="hs-identifier hs-var">poke</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr a
forall a b. Ptr a -&gt; Ptr b
</span><a href="../../base/src/GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070475"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070476"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-identifier">storableToF</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">FP</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">sizeOf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">undefined</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">x</span><span> </span><span class="hs-identifier">op</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-214"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">ptrToWordPtr</span><span> </span><span class="hs-identifier">op</span><span class="hs-special">)</span><span> </span><span class="hs-special">`</span><span class="hs-identifier">mod</span><span class="hs-special">`</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">alignment</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">undefined</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-operator">==</span><span> </span><span class="hs-number">0</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">poke</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">castPtr</span><span> </span><span class="hs-identifier">op</span><span class="hs-special">)</span><span> </span><span class="hs-identifier">x</span><span>
</span><span id="line-215"></span><span>    </span><span class="hs-keyword">else</span><span> </span><span class="hs-identifier">with</span><span> </span><span class="hs-identifier">x</span><span> </span><span class="hs-operator">$</span><span> </span><span class="hs-glyph">\</span><span class="hs-identifier">tp</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">copyBytes</span><span> </span><span class="hs-identifier">op</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">castPtr</span><span> </span><span class="hs-identifier">tp</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">sizeOf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">undefined</span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-identifier">a</span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-218"></span><span class="hs-comment">{-
{-# INLINE CONLIKE liftIOF #-}
liftIOF :: FixedPrim a -&gt; FixedPrim (IO a)
liftIOF (FP l io) = FP l (\xWrapped op -&gt; do x &lt;- xWrapped; io x op)
-}</span><span>
</span><span id="line-223"></span><span>
</span><span id="line-224"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-225"></span><span class="hs-comment">-- Bounded-size builder primitives</span><span>
</span><span id="line-226"></span><span class="hs-comment">------------------------------------------------------------------------------</span><span>
</span><span id="line-227"></span><span>
</span><span id="line-228"></span><span class="hs-comment">-- | A builder primitive that always results in sequence of bytes that is no longer</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- than a pre-determined bound.</span><span>
</span><span id="line-230"></span><span class="hs-keyword">data</span><span> </span><span id="BoundedPrim"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-var">BoundedPrim</span></a></span></span><span> </span><span id="local-6989586621679070598"><span class="annot"><a href="#local-6989586621679070598"><span class="hs-identifier hs-type">a</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="BP"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span></span><span> </span><span class="hs-pragma">{-# UNPACK</span><span> </span><span class="hs-pragma">#-}</span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070598"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-231"></span><span>
</span><span id="line-232"></span><span class="hs-comment">-- | The bound on the size of sequences of bytes generated by this 'BoundedPrim'.</span><span>
</span><span id="line-233"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#sizeBound"><span class="hs-pragma hs-type">sizeBound</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-234"></span><span id="local-6989586621679070584"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#sizeBound"><span class="hs-identifier hs-type">sizeBound</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070584"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-235"></span><span id="sizeBound"><span class="annot"><span class="annottext">sizeBound :: forall a. BoundedPrim a -&gt; Int
</span><a href="Data.ByteString.Builder.Prim.Internal.html#sizeBound"><span class="hs-identifier hs-var hs-var">sizeBound</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070472"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070472"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070472"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-236"></span><span>
</span><span id="line-237"></span><span class="hs-comment">-- | @since 0.10.12.0</span><span>
</span><span id="line-238"></span><span id="local-6989586621679070471"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#boundedPrim"><span class="hs-identifier hs-type">boundedPrim</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070471"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070471"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-239"></span><span id="boundedPrim"><span class="annot"><span class="annottext">boundedPrim :: forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#boundedPrim"><span class="hs-identifier hs-var hs-var">boundedPrim</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span>
</span><span id="line-240"></span><span>
</span><span id="line-241"></span><span class="hs-pragma">{-# DEPRECATED</span><span> </span><span class="hs-pragma">boudedPrim</span><span> </span><span class="hs-pragma">&quot;Use 'boundedPrim' instead&quot;</span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-242"></span><span id="local-6989586621679070470"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#boudedPrim"><span class="hs-identifier hs-type">boudedPrim</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070470"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070470"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-243"></span><span id="boudedPrim"><span class="annot"><span class="annottext">boudedPrim :: forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#boudedPrim"><span class="hs-identifier hs-var hs-var">boudedPrim</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runB"><span class="hs-pragma hs-type">runB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-246"></span><span id="local-6989586621679070580"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#runB"><span class="hs-identifier hs-type">runB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070580"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070580"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="../../base/src/GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-247"></span><span id="runB"><span class="annot"><span class="annottext">runB :: forall a. BoundedPrim a -&gt; a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#runB"><span class="hs-identifier hs-var hs-var">runB</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679070469"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070469"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070469"><span class="hs-identifier hs-var">io</span></a></span><span>
</span><span id="line-248"></span><span>
</span><span id="line-249"></span><span class="hs-comment">-- | Change a 'BoundedPrim' such that it first applies a function to the</span><span>
</span><span id="line-250"></span><span class="hs-comment">-- value to be encoded.</span><span>
</span><span id="line-251"></span><span class="hs-comment">--</span><span>
</span><span id="line-252"></span><span class="hs-comment">-- Note that 'BoundedPrim's are 'Contravariant'</span><span>
</span><span id="line-253"></span><span class="hs-comment">-- &lt;http://hackage.haskell.org/package/contravariant&gt;. Hence, the following</span><span>
</span><span id="line-254"></span><span class="hs-comment">-- laws hold.</span><span>
</span><span id="line-255"></span><span class="hs-comment">--</span><span>
</span><span id="line-256"></span><span class="hs-comment">-- &gt;contramapB id = id</span><span>
</span><span id="line-257"></span><span class="hs-comment">-- &gt;contramapB f . contramapB g = contramapB (g . f)</span><span>
</span><span id="line-258"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-pragma hs-type">contramapB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-259"></span><span id="local-6989586621679070467"><span id="local-6989586621679070468"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-identifier hs-type">contramapB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070468"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679070467"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070467"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070468"><span class="hs-identifier hs-type">b</span></a></span></span></span><span>
</span><span id="line-260"></span><span id="contramapB"><span class="annot"><span class="annottext">contramapB :: forall b a. (b -&gt; a) -&gt; BoundedPrim a -&gt; BoundedPrim b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-identifier hs-var hs-var">contramapB</span></a></span></span><span> </span><span id="local-6989586621679070466"><span class="annot"><span class="annottext">b -&gt; a
</span><a href="#local-6989586621679070466"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070465"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070465"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621679070464"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070464"><span class="hs-identifier hs-var">io</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (b -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim b
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070465"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070463"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070463"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679070462"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070462"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070464"><span class="hs-identifier hs-var">io</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">b -&gt; a
</span><a href="#local-6989586621679070466"><span class="hs-identifier hs-var">f</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070463"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070462"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-261"></span><span>
</span><span id="line-262"></span><span class="hs-comment">-- | The 'BoundedPrim' that always results in the zero-length sequence.</span><span>
</span><span id="line-263"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyB"><span class="hs-pragma hs-type">emptyB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-264"></span><span id="local-6989586621679070576"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#emptyB"><span class="hs-identifier hs-type">emptyB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070576"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-265"></span><span id="emptyB"><span class="annot"><span class="annottext">emptyB :: forall a. BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#emptyB"><span class="hs-identifier hs-var hs-var">emptyB</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="annot"><span class="annottext">a
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679070460"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070460"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070460"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-266"></span><span>
</span><span id="line-267"></span><span class="hs-comment">-- | Encode a pair by encoding its first component and then its second component.</span><span>
</span><span id="line-268"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairB"><span class="hs-pragma hs-type">pairB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-269"></span><span id="local-6989586621679070458"><span id="local-6989586621679070459"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#pairB"><span class="hs-identifier hs-type">pairB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070459"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070458"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070459"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="#local-6989586621679070458"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-270"></span><span id="pairB"><span class="annot"><span class="annottext">pairB :: forall a b. BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (a, b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#pairB"><span class="hs-identifier hs-var hs-var">pairB</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070455"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070455"><span class="hs-identifier hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679070454"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070454"><span class="hs-identifier hs-var">io1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070453"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070453"><span class="hs-identifier hs-var">b2</span></a></span></span><span> </span><span id="local-6989586621679070452"><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070452"><span class="hs-identifier hs-var">io2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-271"></span><span>    </span><span class="annot"><span class="annottext">Int
-&gt; ((a, b) -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim (a, b)
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070455"><span class="hs-identifier hs-var">b1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070453"><span class="hs-identifier hs-var">b2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679070451"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070451"><span class="hs-identifier hs-var">x1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679070450"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070450"><span class="hs-identifier hs-var">x2</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679070449"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070449"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070454"><span class="hs-identifier hs-var">io1</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070451"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070449"><span class="hs-identifier hs-var">op</span></a></span><span> </span><span class="annot"><span class="annottext">IO (Ptr Word8) -&gt; (Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; IO (Ptr Word8)
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; (a -&gt; m b) -&gt; m b
</span><a href="../../base/src/GHC.Base.html#%3E%3E%3D"><span class="hs-operator hs-var">&gt;&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070452"><span class="hs-identifier hs-var">io2</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070450"><span class="hs-identifier hs-var">x2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-272"></span><span>
</span><span id="line-273"></span><span class="hs-comment">-- | Encode an 'Either' value using the first 'BoundedPrim' for 'Left'</span><span>
</span><span id="line-274"></span><span class="hs-comment">-- values and the second 'BoundedPrim' for 'Right' values.</span><span>
</span><span id="line-275"></span><span class="hs-comment">--</span><span>
</span><span id="line-276"></span><span class="hs-comment">-- Note that the functions 'eitherB', 'pairB', and 'contramapB' (written below</span><span>
</span><span id="line-277"></span><span class="hs-comment">-- using '&gt;$&lt;') suffice to construct 'BoundedPrim's for all non-recursive</span><span>
</span><span id="line-278"></span><span class="hs-comment">-- algebraic datatypes. For example,</span><span>
</span><span id="line-279"></span><span class="hs-comment">--</span><span>
</span><span id="line-280"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-281"></span><span class="hs-comment">--maybeB :: BoundedPrim () -&gt; BoundedPrim a -&gt; BoundedPrim (Maybe a)</span><span>
</span><span id="line-282"></span><span class="hs-comment">--maybeB nothing just = 'maybe' (Left ()) Right '&gt;$&lt;' eitherB nothing just</span><span>
</span><span id="line-283"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-284"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#eitherB"><span class="hs-pragma hs-type">eitherB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-285"></span><span id="local-6989586621679070569"><span id="local-6989586621679070570"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#eitherB"><span class="hs-identifier hs-type">eitherB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070570"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070569"><span class="hs-identifier hs-type">b</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070570"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070569"><span class="hs-identifier hs-type">b</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-286"></span><span id="eitherB"><span class="annot"><span class="annottext">eitherB :: forall a b.
BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (Either a b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#eitherB"><span class="hs-identifier hs-var hs-var">eitherB</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070446"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070446"><span class="hs-identifier hs-var">b1</span></a></span></span><span> </span><span id="local-6989586621679070445"><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070445"><span class="hs-identifier hs-var">io1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-type">BP</span></a></span><span> </span><span id="local-6989586621679070444"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070444"><span class="hs-identifier hs-var">b2</span></a></span></span><span> </span><span id="local-6989586621679070443"><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070443"><span class="hs-identifier hs-var">io2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-287"></span><span>    </span><span class="annot"><span class="annottext">Int
-&gt; (Either a b -&gt; Ptr Word8 -&gt; IO (Ptr Word8))
-&gt; BoundedPrim (Either a b)
forall a.
Int -&gt; (a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)) -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#BP"><span class="hs-identifier hs-var">BP</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#max"><span class="hs-identifier hs-var">max</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070446"><span class="hs-identifier hs-var">b1</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679070444"><span class="hs-identifier hs-var">b2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-288"></span><span>        </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070441"><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679070441"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span id="local-6989586621679070440"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070440"><span class="hs-identifier hs-var">op</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either a b
</span><a href="#local-6989586621679070441"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="annot"><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679070439"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070439"><span class="hs-identifier hs-var">x1</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">a -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070445"><span class="hs-identifier hs-var">io1</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070439"><span class="hs-identifier hs-var">x1</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070440"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679070438"><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070438"><span class="hs-identifier hs-var">x2</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">b -&gt; Ptr Word8 -&gt; IO (Ptr Word8)
</span><a href="#local-6989586621679070443"><span class="hs-identifier hs-var">io2</span></a></span><span> </span><span class="annot"><span class="annottext">b
</span><a href="#local-6989586621679070438"><span class="hs-identifier hs-var">x2</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679070440"><span class="hs-identifier hs-var">op</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-289"></span><span>
</span><span id="line-290"></span><span class="hs-comment">-- | Conditionally select a 'BoundedPrim'.</span><span>
</span><span id="line-291"></span><span class="hs-comment">-- For example, we can implement the ASCII primitive that drops characters with</span><span>
</span><span id="line-292"></span><span class="hs-comment">-- Unicode codepoints above 127 as follows.</span><span>
</span><span id="line-293"></span><span class="hs-comment">--</span><span>
</span><span id="line-294"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-295"></span><span class="hs-comment">--charASCIIDrop = 'condB' (&lt; \'\\128\') ('liftFixedToBounded' 'Data.ByteString.Builder.Prim.char7') 'emptyB'</span><span>
</span><span id="line-296"></span><span class="hs-comment">-- @</span><span>
</span><span id="line-297"></span><span class="hs-pragma">{-# INLINE CONLIKE</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#condB"><span class="hs-pragma hs-type">condB</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-298"></span><span id="local-6989586621679070565"><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#condB"><span class="hs-identifier hs-type">condB</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679070565"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070565"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070565"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Data.ByteString.Builder.Prim.Internal.html#BoundedPrim"><span class="hs-identifier hs-type">BoundedPrim</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679070565"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-299"></span><span id="condB"><span class="annot"><span class="annottext">condB :: forall a.
(a -&gt; Bool) -&gt; BoundedPrim a -&gt; BoundedPrim a -&gt; BoundedPrim a
</span><a href="Data.ByteString.Builder.Prim.Internal.html#condB"><span class="hs-identifier hs-var hs-var">condB</span></a></span></span><span> </span><span id="local-6989586621679070437"><span class="annot"><span class="annottext">a -&gt; Bool
</span><a href="#local-6989586621679070437"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span id="local-6989586621679070436"><span class="annot"><span class="annottext">BoundedPrim a
</span><a href="#local-6989586621679070436"><span class="hs-identifier hs-var">be1</span></a></span></span><span> </span><span id="local-6989586621679070435"><span class="annot"><span class="annottext">BoundedPrim a
</span><a href="#local-6989586621679070435"><span class="hs-identifier hs-var">be2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-300"></span><span>    </span><span class="annot"><span class="annottext">(a -&gt; Either a a) -&gt; BoundedPrim (Either a a) -&gt; BoundedPrim a
forall b a. (b -&gt; a) -&gt; BoundedPrim a -&gt; BoundedPrim b
</span><a href="Data.ByteString.Builder.Prim.Internal.html#contramapB"><span class="hs-identifier hs-var">contramapB</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679070434"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070434"><span class="hs-identifier hs-var">x</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">a -&gt; Bool
</span><a href="#local-6989586621679070437"><span class="hs-identifier hs-var">p</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070434"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">a -&gt; Either a a
forall a b. a -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070434"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">a -&gt; Either a a
forall a b. b -&gt; Either a b
</span><a href="../../base/src/Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679070434"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BoundedPrim a -&gt; BoundedPrim a -&gt; BoundedPrim (Either a a)
forall a b.
BoundedPrim a -&gt; BoundedPrim b -&gt; BoundedPrim (Either a b)
</span><a href="Data.ByteString.Builder.Prim.Internal.html#eitherB"><span class="hs-identifier hs-var">eitherB</span></a></span><span> </span><span class="annot"><span class="annottext">BoundedPrim a
</span><a href="#local-6989586621679070436"><span class="hs-identifier hs-var">be1</span></a></span><span> </span><span class="annot"><span class="annottext">BoundedPrim a
</span><a href="#local-6989586621679070435"><span class="hs-identifier hs-var">be2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-301"></span></pre></body></html>